package controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import pojo.User;
import service.UserService;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/users")
    private ModelAndView findByPage(ModelAndView mav,
                                    @RequestParam(value = "pageNum",required = false, defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize",required = false, defaultValue = "2")Integer pageSize) {
        PageInfo<User> pageInfo = userService.findByPage(pageNum, pageSize);

        mav.addObject("data", pageInfo);
        mav.setViewName("userList.jsp");
        return mav;
    }

    @RequestMapping("/user/findAll")
    private List<User> findAll() {
        return userService.findAll();
    }
}
